class UpdateResourceJob {

    // fire every three hours; every hour between 03:00-06:00
    // for testing you can use "0 * * * * ?" to fire every minute
    def cronExpression = "0 0 0,3,4,5,6,9,12,15,18,21 * * ?"

    def group = "updateResource"

    def time_period = 3 // days
    def lot_size = 200

    def pingService

    def execute() {
        // find top N resources that not updated for a specific time
        def t = new java.sql.Timestamp((new Date() - time_period).time)
        def list = Resource.findAllByLastUpdatedLessThanAndAutoFetch(t, true, [max:lot_size, sort:"lastUpdated", order:"asc"])
        list.each {
            log.debug ("update (job) " + it.url)
            pingService.pingResource(it)
        }
    }

}
